package com.xintonghua.bussiness.util;

import android.content.Context;
import android.text.TextUtils;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.xintonghua.bussiness.R;
import com.xintonghua.bussiness.api.BaseApi;

/**
 * 作者：wanxianyi
 * 时间：2018/3/28.
 * 包名：com.xintonghua.bussiness.util
 */

public class GlideUtils {

    private static String getImageUrl(String url) {
        if (!TextUtils.isEmpty(url)&&url.startsWith("http")) {
            return url;
        } else {
            return BaseApi.IMAGE_URL + url;
        }

    }

    public static void load(Context context, ImageView imageView, String url) {
        Glide.with(context).load(getImageUrl(url)).error(R.mipmap.ic_image_loading).into(imageView);
    }

    public static void load(Context context, ImageView imageView, String url, int error) {
        Glide.with(context).load(getImageUrl(url)).error(error).into(imageView);
    }

    public static void loadCricle(Context context, ImageView imageView, String url) {
        Glide.with(context).load(getImageUrl(url)).error(R.mipmap.ic_image_loading).transform(new GlideCircleTransform(context)).into(imageView);
    }

    public static void loadCricle(Context context, ImageView imageView, String url, int error) {
        Glide.with(context).load(getImageUrl(url)).error(error).transform(new GlideCircleTransform(context)).into(imageView);
    }
}
